import React, { Component } from 'react'
import { connect } from 'dva';

import { Button } from 'antd'

import ListItem from "@/components/ListCard";

import { KEYS } from '../enum';

interface Props {
  dispatch?: Function,
  details: {
    id: number,
    companyId: number
  },
  match: {
    params: {
      id: number
    }
  },
}

@connect(({ build_floor_area }) => ({
  details: build_floor_area.details
}))
class Details extends Component<Props, any> {

  state = {
    data: []
  }

  componentDidMount() {
    const { dispatch, match } = this.props;
    const { params } = match;

    dispatch({
      type: 'build_floor_area/queryInfoById',
      payload: params.id
    }).then(() => {
      const { details } = this.props;
      const data = [];

      KEYS.forEach(item => {
        data.push({
          name: item.name,
          value: details[item.key]
        })
      })

      this.setState({
        data
      })
    })
  }

  render() {
    return (
      <>
        <ListItem data={ this.state.data }/>
        <Button onClick={ () => { window.history.back()} } >
          返回
        </Button>
      </>
    );
  }
}

export default Details;
